package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.UUID;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Canshu;
import com.ruoyi.system.service.ICanshuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统管理-参数管理Controller
 * 
 * @author zxl
 * @date 2023-05-26
 */
@Controller
@RequestMapping("/system/canshu")
public class CanshuController extends BaseController
{
    private String prefix = "system/canshu";

    @Autowired
    private ICanshuService canshuService;

    @RequiresPermissions("system:canshu:view")
    @GetMapping()
    public String canshu()
    {
        return prefix + "/canshu";
    }

    /**
     * 查询系统管理-参数管理列表
     */
    @RequiresPermissions("system:canshu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Canshu canshu)
    {
        startPage();
        List<Canshu> list = canshuService.selectCanshuList(canshu);
        return getDataTable(list);
    }

    /**
     * 导出系统管理-参数管理列表
     */
    @RequiresPermissions("system:canshu:export")
    @Log(title = "系统管理-参数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Canshu canshu)
    {
        List<Canshu> list = canshuService.selectCanshuList(canshu);
        ExcelUtil<Canshu> util = new ExcelUtil<Canshu>(Canshu.class);
        return util.exportExcel(list, "系统管理-参数管理数据");
    }

    /**
     * 新增系统管理-参数管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统管理-参数管理
     */
    @RequiresPermissions("system:canshu:add")
    @Log(title = "系统管理-参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Canshu canshu)
    {
        canshu.setIsvalid(1l);
        canshu.setID(UUID.randomUUID().toString());
        return toAjax(canshuService.insertCanshu(canshu));
    }

    /**
     * 修改系统管理-参数管理
     */
    @RequiresPermissions("system:canshu:edit")
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") String ID, ModelMap mmap)
    {
        Canshu canshu = canshuService.selectCanshuByID(ID);
        mmap.put("canshu", canshu);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统管理-参数管理
     */
    @RequiresPermissions("system:canshu:edit")
    @Log(title = "系统管理-参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Canshu canshu)
    {
        return toAjax(canshuService.updateCanshu(canshu));
    }

    /**
     * 删除系统管理-参数管理
     */
    @RequiresPermissions("system:canshu:remove")
    @Log(title = "系统管理-参数管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(canshuService.deleteCanshuByIDs(ids));
    }
}
